﻿
using System;
using System.Threading.Tasks;

public static class AsyncPowerCalculator
{
    
    public static async Task<double> CalculateAsync(double a, double b)
    {
        
        if (a <= 1 || a >= 10 || b <= 1 || b >= 10)
            throw new ArgumentOutOfRangeException("a和b必须是大于1且小于10的实数");
        Task<double> taskA = CalculatePowerAsync(a, 58);
        Task<double> taskB = CalculatePowerAsync(b, 50);
        double resultA = await taskA;
        double resultB = await taskB;
        return resultA + resultB;
    }
    private static Task<double> CalculatePowerAsync(double x, int power)
    {
        return Task.Run(() => Math.Pow(x, power));
    }
}
class Program
{
    static async Task Main(string[] args)
    {
        Console.WriteLine("===== 异步计算 a^58 + b^50 =====");

        try
        {
            double a = 2.5;
            double b = 3.2;

            Console.WriteLine($"计算：{a}^58 + {b}^50");
            DateTime start = DateTime.Now;
            double result = await AsyncPowerCalculator.CalculateAsync(a, b);

            TimeSpan cost = DateTime.Now - start;
            Console.WriteLine($"结果：{result:F6}（科学计数法：{result:E4}）");
            Console.WriteLine($"计算耗时：{cost.TotalMilliseconds:F2} 毫秒");
        }
        catch (Exception ex)
        {
            Console.WriteLine($"错误：{ex.Message}");
        }

        Console.ReadKey();
    }
}